//
//  LDClassCell.m
//  Gift
//
//  Created by 李迪 on 15/11/12.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LDClassCell.h"
#import "BaseHeader.h"

@interface LDClassCell ()
@property(nonatomic, retain)UIImageView *imageview;
@property(nonatomic, retain)UILabel *name;

@end

@implementation LDClassCell


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageview = [[UIImageView alloc]init];
        [self.imageview setBackgroundColor:[UIColor whiteColor]];
        [self.contentView addSubview:self.imageview];
        [_imageview release];
        self.name = [[UILabel alloc]init];
        [self.name setBackgroundColor:[UIColor whiteColor]];
        self.name.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.name];
        [_name release];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.imageview setFrame:CGRectMake(10, 0, 50, 50)];
    [self.name setFrame:CGRectMake(0, 50 , 70, 20)];
    
    
    //夜间模式
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"night"];
    if ([passWord isEqualToString:@"yes"]) {
        self.name.textColor = [UIColor whiteColor];
        self.name.backgroundColor = [UIColor blackColor];
        self.imageview.backgroundColor = [UIColor blackColor];
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNot:) name:@"lidi" object:nil];
}

//夜间方法
- (void)handleNot:(NSNotification *)Not{
    NSString *passWord = [Not object];
    if ([passWord isEqualToString:@"yes"]) {
        self.name.textColor = [UIColor whiteColor];
        self.name.backgroundColor = [UIColor blackColor];
        self.imageview.backgroundColor = [UIColor blackColor];

    }else if ([passWord isEqualToString:@"no"]){
        self.name.textColor = [UIColor blackColor];
        self.name.backgroundColor = [UIColor whiteColor];
        self.imageview.backgroundColor = [UIColor whiteColor];

    }
}



- (void)setModel:(ClassificationModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.icon_url]];
    self.name.text = model.name;
  
}



@end
